﻿@model List<iChip.Hotspots.Models.HotspotsObject>
@{
    ViewBag.Title = "Quản Lý Hotspots";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}
<!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->
<div id="addHotspots" class="modal fade" tabindex="-1" data-width="400">
    <div class="modal-dialog">
        <div class="modal-content">
            @{Html.RenderAction("AddHotspots", "Admin");}
        </div>
    </div>
</div>
<!-- /.modal -->
<!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->
<!-- BEGIN PAGE HEADER-->
<div class="row">
    <div class="col-md-12">
        <!-- BEGIN PAGE TITLE & BREADCRUMB-->
        <h3 class="page-title">
            Danh sách Hotspots
        </h3>
        <ul class="page-breadcrumb breadcrumb">
            <li>
                <i class="icon-home"></i>
                <a href="/Admin">Tổng quan</a>
                <i class="icon-angle-right"></i>
            </li>
            <li><a href="#">Quản Lý Hotspots</a></li>
            <li class="pull-right">
            </li>
        </ul>
        <!-- END PAGE TITLE & BREADCRUMB-->
    </div>
</div>
<!-- END PAGE HEADER-->
<div class="row">
    <div class="col-md-12 col-sm-12">
        <!-- BEGIN EXAMPLE TABLE PORTLET-->
        <div class="portlet">
            <div class="portlet-title">
                <div class="caption"><i class="icon-signal"></i>Danh sách Hotspots</div>
                <div class="actions">
                    <a class="btn red" id="aAdd"><i class="icon-plus"></i> Thêm Hotspot</a>
                </div>
            </div>
            <div class="portlet-body">
                @if (Model != null && Model.Count > 0)
                {
                    <div class="table-responsive">
                        <table class ="table table-striped table-bordered table-advance table-hover" id="tbHotspots">
                            <thead>
                                <tr>
                                    <th style="width:8px;">#</th>
                                    <th>Tên Hotspots</th>
                                    <th>Mac</th>
                                    <th>IP</th>
                                    <th>Loại</th>
                                    <th>Địa chỉ</th>
                                    <th>Trạng thái</th>
                                    <th>Tùy chọn</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (var item in Model)
                                {
                                    <tr class="odd gradeX" id="trHot_@item.Hotspot_Id">
                                        <td>@item.Counter</td>
                                        <td>@item.Hotspot_Name</td>
                                        <td>@item.Hotspot_Mac</td>
                                        <td>@item.Hotspot_Ip</td>
                                        <td>@item.Hotspot_Type</td>
                                        <td>@item.Hotspot_Address</td>

                                        <td>
                                            @if (item.Hotspot_Status)
                                            {
                                                <span class="label label-sm label-success">Online</span>
                                            }
                                            else
                                            {
                                                <span class="label label-sm label-warning">Offline</span>
                                            }
                                        </td>
                                        <td>
                                          
                                            <a href="@Url.Action("Splashs", "Admin", new { Hotspot_id = @item.Hotspot_Id, Hotspot_mac = @item.Hotspot_Mac})" class="btn btn-default btn-xs green"><i class="icon-list-alt"></i>&nbsp;Splash</a>&nbsp;
                                            <a name="aEdit" data-url="@Url.Action("AddHotspots","Admin")" data-id="@item.Hotspot_Id" class="btn btn-default btn-xs purple"><i class="icon-pencil"></i> Sửa</a>&nbsp;
                                            <a name="aDel" data-id="@item.Hotspot_Id" class="btn btn-default btn-xs red"><i class="icon-trash"></i> Xóa</a>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                            </table>
</div>

                }
            </div>
        </div>
        <!-- END EXAMPLE TABLE PORTLET-->
    </div>
</div>

<div class="clearfix"></div>
<div class="row ">
    <div class="col-md-12 col-sm-12">
        <!-- BEGIN REGIONAL STATS PORTLET-->
        <div class="portlet">
            <div class="portlet-title">
                <div class="caption"><i class="icon-globe"></i>Bản đồ hotspot</div>
                <div class="tools">
                    <a href="" class="collapse"></a>
                    <a href="#portlet-config" data-toggle="modal" class="config"></a>
                    <a href="" class="reload"></a>
                    <a href="" class="remove"></a>
                </div>
            </div>
            <div class="portlet-body">
                @{Html.RenderAction("GenMapHotspots", "Admin");}
            </div>
        </div>
        <!-- END REGIONAL STATS PORTLET-->
    </div>
</div>
<div class="clearfix"></div>

@section Scripts {
<script src="/AssetsAdmin/scripts/index.js" type="text/javascript"></script>
    <script>
       
        $("[name=aEdit]").click(function (e) {
            e.preventDefault();
            var url = $(this).data("url") + "?Hotspot_id=" + $(this).data("id");
            console.log($(this), $(this).data("id"), $(this).data("url"), url);
            $.get(url, function (data) {
                $('#addHotspots div.modal-content').html(data);
                $('#addHotspots').modal('show');
                App.init(); // initlayout and core plugins

                $('#btEditHotspot').click(function (e) {
                    e.preventDefault();
                    $.ajax({
                        url: '@Url.Action("AddHotspots","Admin")', //this is the submit URL
                        type: 'POST', //or POST
                        data: $('#formaddHotspots').serialize(),
                        success: function (data) {
                            if (data.Status == true) {
                                window.location.reload();
                            }
                            else {
                                $("#lblNote").addClass("red").text(data.Message);
                            }
                        }
                    });
                });
            });
        });

        $("[name=aDel]").click(function (e) {
            e.preventDefault();
            var r = confirm("Bạn có thực sự muốn xóa Hotspot này ra khỏi hệ thống!");
            if (r == true) {
                var id = $(this).data("id");
                $.ajax({
                    url: '@Url.Action("DeleteHotspot", "Admin")', //this is the submit URL
                    type: 'POST', //or POST
                    data: { hotspot_id: id },
                    success: function (data) {
                        if (data.Status == true) {
                            $("#trHot_" + id).remove();
                        }
                        else {
                            alert(data.Message);
                        }
                    }
                });
            }
        });

        $("#aAdd").click(function (e) {
            e.preventDefault();
            $.get('@Url.Action("AddHotspots", "Admin")', function (data) {
                $('#addHotspots div.modal-content').html(data);
                $('#addHotspots').modal('show');
                App.init(); // initlayout and core plugins
                $('#btAddHotspot').click(function (e) {
                    e.preventDefault();
                    $.ajax({
                        url: '@Url.Action("AddHotspots", "Admin")', //this is the submit URL
                        type: 'POST', //or POST
                        data: $('#formaddHotspots').serialize(),
                        success: function (data) {
                            if (data.Status == true) {
                                window.location.reload();
                            }
                            else {
                                $("#lblNote").addClass("red").text(data.Message);
                            }
                        }
                    });
                });
            });
        });
    </script>
}
